import 'package:flutter/material.dart';
import '../../dgg_flutter_date_picker.dart';

class DateTitleWidget extends StatelessWidget {
  DateTitleWidget({
    Key key,
    this.isDark,
    this.pickerTheme,
    @required this.onCancel,
    @required this.onConfirm,
  }) : super(key: key);

  final bool isDark;
  final DatePickerTheme pickerTheme;
  final DateVoidCallback onCancel, onConfirm;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: pickerTheme.titleHeight,
      decoration: BoxDecoration(
        color: isDark?Color.fromRGBO(45, 46, 46, 1):pickerTheme.backgroundColor,
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(12.0),
          topRight: Radius.circular(12.0)
        )
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Container(
            height: pickerTheme.titleHeight,
            child: FlatButton(
              child: _renderCancelWidget(context),
              onPressed: () => this.onCancel()
            ),
          ),
          Expanded(
            child: Container(
              alignment: Alignment.center,
              height: pickerTheme.titleHeight,
              child: pickerTheme.title ?? Text(
                "设置截止时间",
                style: TextStyle(
                  color: isDark ? Color(0xFFE0E0E0) : Color.fromRGBO(51,51,51, 1),
                  fontSize: 18.0
                ),
              ),
            ),
          ),
          Container(
            height: pickerTheme.titleHeight, 
            child: FlatButton(
                child: _renderConfirmWidget(context),
                onPressed: () => this.onConfirm()),
          ),
        ],
      ),
    );
  }

  /// render cancel button widget
  Widget _renderCancelWidget(BuildContext context) {
    Widget cancelWidget = pickerTheme.cancel;
    if (cancelWidget == null) {
      TextStyle textStyle = pickerTheme.cancelTextStyle ??
          TextStyle(
              color: isDark?Color.fromRGBO(134, 134, 134, 1):Theme.of(context).unselectedWidgetColor, fontSize: 16.0);
      cancelWidget =
          Text(DateFormatter.getLocaleCancel(), style: textStyle);
    }
    return cancelWidget;
  }

  /// render confirm button widget
  Widget _renderConfirmWidget(BuildContext context) {
    Widget confirmWidget = pickerTheme.confirm;
    if (confirmWidget == null) {
      TextStyle textStyle = pickerTheme.confirmTextStyle ??
          TextStyle(color: Theme.of(context).primaryColor, fontSize: 16.0);
      confirmWidget =
          Text(DateFormatter.getLocaleDone(), style: textStyle);
    }
    return confirmWidget;
  }
}
